from tqdm import tqdm

FILE = 'test.txt'
OUT_FILE = 'test_toy.txt'

with open('entities.txt', 'r') as f:
    entities = f.readlines()
entities = [e.strip() for e in entities]

with open(FILE, 'r') as f:
    x = f.readlines()

train_toy = list()
with open(OUT_FILE, 'w') as ff:
    for l in tqdm(x):
        h, r, t = l.split()
        if h.strip() in entities and t.strip() in entities:
            ff.write('{}'.format(l))
